<?php
namespace Home\Controller;
use Think\Controller;

class scoreController extends Controller {
    //成绩
    public function index()
    {
        if(strlen(session('std_id'))!=0)
        {
            $field =I('field');
            $order = I('order');
            if ($order == 1) {
                $set_order = 'desc';
            } else {
                $set_order = 'asc';
            }
            if(empty($field))
            {
                $field="std_id";
            }
            //分页
            $total=M('Score')->where(array("std_id"=>session('std_id')))->count();

            if( $total ){
                $perNum=25;
                $Page=new \Think\Page( $total , $perNum );

                $Page->setConfig( 'prev' , "上一页" );//上一页
                $Page->setConfig( 'next' , '下一页' );//下一页
                $Page->setConfig( 'first' , '首页' );//第一页
                $Page->setConfig( 'last' , "末页" );//最后一页
                $Page->setConfig( 'theme' , '%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%' );

                $show=$Page->show();

                $this->assign( 'total' , $total );
                $this->assign( 'page' , $show );

            }

            $score_list=M('Score')->where(array("std_id"=>session('std_id')))->order($field . " " . $set_order)->limit( $Page->firstRow.','.$Page->listRows )->select();
            //select * from go_score order by $field.$set_order limit $Page->firstRow,$Page->listRows
            $this->assign( 'score_list' , $score_list );
            $this->assign('sidebar','score');
            $this->assign('std_id',session('std_id'));
            $this->display( 'score_list' );
        }
        else
        {
            $this->redirect('/Home/Index/index',array(), 0, '');
        }
    }
}